
package com.biglead.wx.controller;



import com.biglead.common.pojo.MiniLoginCodeRequest;
import com.biglead.common.pojo.MiniLoginRequest;
import com.biglead.wx.service.WxAppLoginService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 微信用户相关杢
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wx")
public class WxUserController {


    @Autowired
    private WxAppLoginService wxAppLoginService;

    /**
     * 小程序用户登录
     *
     * @param request
     * @param loginDTO
     * @return
     */
    @ApiOperation(value = "小程序用户登录=code、用户的基本信息")
    @PostMapping("/login_by_userinfo")
    public Map<String,Object> loginMa(HttpServletRequest request, @RequestBody MiniLoginRequest loginDTO) throws WxErrorException {
        return wxAppLoginService.login(loginDTO);
    }
    @ApiOperation(value = "小程序用户登录-只有code")
    @PostMapping("/login_by_code")
    public Map<String,Object> loginMaByCode( @RequestBody MiniLoginCodeRequest loginDTO){
        return wxAppLoginService.loginByCode(loginDTO);
    }

    @ApiOperation(value = "获取用电话")
    @PostMapping("/login_by_phone")
    public Map<String,Object>  phone(@RequestBody MiniLoginRequest loginDTO) throws WxErrorException {
        return wxAppLoginService.phone(loginDTO);
    }
}
